package IO;

import java.io.*;
import java.lang.reflect.Field;

/**
 * Created by ZC_zc on 2016/11/28.
 */
public class copyFile {

    public static void main(String[] args) {

        String fileName1="D:"+File.separator+"test"+File.separator+"never.txt";
        String fileName2="D:"+File.separator+"test"+File.separator+"copy.txt";

        File sourceFile=new File(fileName1);
        File targetFile=new File(fileName2);

        try {
            BufferedInputStream bufferedInputStream=new
                    BufferedInputStream(new FileInputStream(sourceFile));

            BufferedOutputStream bufferedOutputStream=new
                    BufferedOutputStream(new FileOutputStream(targetFile));

            int len=0;

            byte[]  bytes=new byte[1024];
            while ((len=bufferedInputStream.read(bytes,0,bytes.length))!=-1){
                bufferedOutputStream.write(bytes,0,len);
            }
            bufferedOutputStream.close();
            bufferedInputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {

        }
    }
}
